﻿/// <reference path="../../../BasePlatform/Home/home.html" />
/// <reference path="../../../BasePlatform/Home/News_Content.html" />

var baseUrl = getBaseplatformPort();
$(function () {

    News_Platform_List('');//显示列表
    GetPicPath();
    //加载图片
    function GetPicPath()
    {
        $('#picpath').html();
        var data = {
            //mtype: "GetPicpath"
        };
        $.ajax({
            type: "post",
            async: false,
            url: baseUrl + "news/getPicpath",
            //url: "/BaseAshx/NewsManage/News_List.ashx",
            data: data,
            datatype: "json",
            success: function (result) {
                result = JSON.parse(result);
                if (result.code == 200) {
                    var html = "";
                    var table = result.data.table;
                    for (i = 0; i < table.length; i++) {
                        var title = table[i].TITLE;
                        var biaoti = "";
                        if (title.length > 20) {
                            biaoti = title.substr(0, 20) + "...";
                        } else {
                            biaoti = title;
                        }
                        html += '<div style=" background-image:url(' + table[i].PICPATH + ');background-size:360px 235px;">' +
                                   '<div class="box">' +
                                   '<span class="new-title"> ' +
                     '<a href="News_Content.html?id=' +table[i].ID + '">' + biaoti + '</a>' +
                                   '</span></div></div>';
                    }
                    $('#picpath').html(html);

                } else {
                    layer.msg(result.msg, {
                        shade: 0.3,
                        time: 1000 // 1秒关闭
                    });
                    return;
                }
            },
            error: function (error) {
                console.log(error);
            }
        })
    }
    //
    $('.title-color').html('');
    var html = ' <img src="/img/news.png"> &nbsp;<a id="homeBtn" href="home.html" target="_self">首页</a> > <a href="News_List.html">新闻中心</a> ><a><span id="span">平台新闻</span></a>'
    $('.title-color').html(html);
    $('#homeBtn').on('click', function () {
        if (parent.window.$('#homeIframe').length && parent.window.$('#homeBtn').length) {
            parent.window.$('#homeBtn').click();
        }
    });
    //$('#new_List').on('click', '.list-li', function (e) {
    //    var id = $(e.currentTarget).attr('newsId');
    //    GetNews_Platform_List_id(id);
    //})

    //平台新闻
    function News_Platform_List(page, isSecond)
    {
        $('#new_List').html();
        $('#News_Platform').html();
        $('#News_Announcement').html();
        $('#News_Resources').html();
        var data = {
            currentPage: page ? page : 1,
            pageRowNum: 10,
            newsType: "newsType1",
            //mtype: "News_Platform_GetNewsListByTitles",
            pageNum: page || 1, // 请求页码: 1,2,3…
            perPageNum: 10, // 每页条数: 1,2,3…
            title: "",
            author: "",
            startDate: "",
            endDate:"",
        }
        $.ajax({
            type: "post",
            async: false,
            url: baseUrl + "news/getNewsList",
            //url: "/BaseAshx/NewsManage/News_Platform.ashx",
            data:data,
            datatype: "json",
            success: function (result) {
                result = JSON.parse(result);
                if (result.code == 200) {
                    if (!result.data.table || result.data.total == 0) {
                        layer.msg('无数据', {
                            shade: 0.3,
                            time: 1000 // 1秒关闭
                        });
                        return;
                    }
                    var html = "";
                    result.data.table.map(function (item, index) {//循环获取到的数据
                        var id = item.TITLEID;
                        var colb = item.TITLE;
                        var content = "";
                        if (colb.length > 40) {
                            content = colb.substr(0,40) + "...";
                        } else {
                            content = colb;
                        }
                        html += '<li class="list-li" newsId="'+ id +'">' +
                            '<span class="circle-span"></span>' +
                            '<span class="font-span"><a href="News_Content.html?id='+id+'"> &nbsp;&nbsp;&nbsp;&nbsp;' + content + '</a> </span>' +
                            '<span class="span-date"> ' + item.CREATETIME + '</span>' + '</li>';

                        $('#new_List').html(html);
                      
                        //var content = item.TITLE;
                       
                       
                        if (result.data.total > 24) {
                            var data = {
                                pageTotal: Math.ceil(result.data.total / 24),
                                pageAmount: 24, // 每页多少条
                                dataTotal: result.data.total,
                                curPage: 1
                            };
                            if (isSecond) {
                                return;
                            };
                            new Page({
                                id: 'page',
                                pageTotal: data.pageTotal, //必填,总页数（最少1页）
                                pageAmount: data.pageAmount, //每页多少条
                                dataTotal: data.dataTotal, //总共多少条数据（至少1条）
                                curPage: data.curPage, //初始页码,不填默认为1
                                pageSize: data.pageSize, //分页个数,不填默认为5
                                showPageTotalFlag: true, //是否显示数据统计,不填默认不显示
                                showSkipInputFlag: true, //是否支持跳转,不填默认不显示
                                getPage: function (page) {
                                    // 请求数据
                                    News_Platform_List(page, true);
                                }
                            });
                        }
                    })
                }
                //else {
                //    layer.msg(result.msg, {
                //        shade: 0.3,
                //        time: 1000 // 1秒关闭
                //    });
                //    return;
                //}
                var html1 = "";
                var table = result.data.table;
                var colb = ""
                if (table.length <= 5) {//小于5条等于自身  大于5条等于5
                    return;
                }
                for (i = 0; i < 5; i++) {
                    var content = table[i].TITLE;
                    var id = table[i].TITLEID;
                    if (content.length >= 21) {
                        colb = content.substr(0,21) + "...";
                    } else {
                        colb = content;
                    }
                    html1 += '<li><span class="circle-list"></span>' +
                   '<span class="new-list"><a href="News_Content.html?id=' + id + '">' + colb + '</a></span>' +
                   '</li>';

                }
                $('#News_Platform').html(html1);
            },
            error: function (error) {
                console.log(error);
            }
            
        });
        $.ajax({
            type: "post",
            async: false,
            url: baseUrl + "news/getNewsList",
            //url: "/BaseAshx/NewsManage/News_Announcement.ashx",
            data: {
                currentPage: page ? page : 1,
                pageRowNum: 5,
                newsType: "newsType2",
                //mtype: "News_Announcement_GetNewsListByTitles",
                pageNum: page || 1, // 请求页码: 1,2,3…
                perPageNum: 5, // 每页条数: 1,2,3…
                title: "",
                author: "",
                startDate: "",
                endDate: "",
            },
            datatype: "json",
            success: function (result) {
                result = JSON.parse(result);
                if (result.code == 200) {
                    if (!result.data.table || result.data.total == 0) {
                        layer.msg('无数据', {
                            shade: 0.3,
                            time: 1000
                        });
                        return;
                    }
                    var html2 = "";
                    result.data.table.map(function (item, index) {
                        var content = item.TITLE;
                        var id = item.TITLEID;
                        var colb = ""
                        if (content.lenght > 21) {
                            colb = content.substr(0, 21) + "...";
                        } else {
                            colb = content;
                        }
                        html2 += '<li><span class="circle-list"></span>' +
                            '<span class="new-list"><a href="News_Content.html?id=' + id + '">' + colb + '</a></span>' +
                            '</li>';
                        $('#News_Announcement').html(html2);
                    })
                }
                //else {
                //    layer.msg(result.msg, {
                //        shade: 0.3,
                //        time: 1000 // 1秒关闭
                //    });
                //    return;
                //}
            },
            error: function (error) {
                console.log(error);
            }
        });
        $.ajax({
            type: "post",
            async: false,
            url: baseUrl + "news/getNewsList",
            //url: "/BaseAshx/NewsManage/News_Resources.ashx",
            data: {
                currentPage: page ? page : 1,
                pageRowNum: 5,
                newsType: "newsType3",
                //mtype: "News_Resources_GetNewsListByTitle",
                pageNum: page || 1, // 请求页码: 1,2,3…
                perPageNum: 5, // 每页条数: 1,2,3…
                title: "",
                author: "",
                startDate: "",
                endDate: "",
            },
            datatype: "json",
            success: function (result) {
                result = JSON.parse(result);
                if (result.code == 200) {
                    if (!result.data.table || result.data.total == 0) {
                        layer.msg('无数据', {
                            shade: 0.3,
                            time: 1000
                        });
                        return;
                    }
                    var html3 = "";
                    result.data.table.map(function (item, index) {
                        var content = item.TITLE;
                        var id = item.TITLEID;
                        var colb = ""
                        if (content.lenght >21) {
                            colb = content.substr(0, 21) + "...";
                        } else {
                            colb = content;
                        }
                        html3 += '<li><span class="circle-list"></span>' +
                            '<span class="new-list"><a href="News_Content.html?id=' + id + '">' + colb + '</a></span>' +
                            '</li>';
                        $('#News_Resources').html(html3);
                    })
                }
                //else {
                //    layer.msg(result.msg, {
                //        shade: 0.3,
                //        time: 1000 // 1秒关闭
                //    });
                //    return;
                //}
            },
            error: function (error) {
                console.log(error);
            }
        });
    }
    //平台新闻的更多
    $('#news_more1').on('click', function () {
        $('#span').html("");
        var title = "平台新闻";
        $('#span').html(title);
        News_Platform_List('');
    })

    //最新通告
    function News_Announcement_List(page, isSecond) {
        $('#new_List').html();
        var data = {
            currentPage: page ? page : 1,
            pageRowNum: 24,
            newsType: "newsType2",
            //mtype: "News_Announcement_GetNewsListByTitles",
            pageNum: page || 1,
            perPageNum: 24,
            Title: "",
            Author: "",
            startDate: "",
            endDate:"",
        }
        $.ajax({
            type: "post",
            async: false,
            url: baseUrl + "news/getNewsList",
            //url: "/BaseAshx/NewsManage/News_Announcement.ashx",
            data: data,
            datatype: "json",
            success: function (result) {
                result = JSON.parse(result);
                if (result.code == 200) {
                    if (!result.data.table || result.data.total == 0) {
                        layer.msg('无数据', {
                            shade: 0.3,
                            time: 1000
                        });
                        return;
                    }
                    var html = "";
                    result.data.table.map(function (item, index) {
                        var colb = item.TITLE;
                        var id = item.TITLEID;
                        var content = "";
                        if (colb.lenght > 40) {
                            content = colb.substr(0, 40) + "...";
                        } else {
                            content = colb;
                        }
                        html += '<li class="list-li">' +
                            ' <span class="circle-span"></span>' +
                            '<span class="font-span"><a href="News_Content.html?id=' + id + '"> &nbsp;&nbsp;&nbsp;&nbsp;' + content + '</a></span>' +
                            '<span class="span-date">' + item.CREATETIME + '</span>' +
                            '</li>';
                        $('#new_List').html(html);
                        if (result.data.total > 24) {
                            var data = {
                                pageTotal: Math.ceil(result.data.total / 24),
                                pageAmount: 24, // 每页多少条
                                dataTotal: result.data.total,
                                curPage: 1
                            };
                            if (isSecond) {
                                return;
                            };


                            new Page({
                                id: 'page',
                                pageTotal: data.pageTotal, //必填,总页数（最少1页）
                                pageAmount: data.pageAmount, //每页多少条
                                dataTotal: data.dataTotal, //总共多少条数据（至少1条）
                                curPage: data.curPage, //初始页码,不填默认为1
                                pageSize: data.pageSize, //分页个数,不填默认为5
                                showPageTotalFlag: true, //是否显示数据统计,不填默认不显示
                                showSkipInputFlag: true, //是否支持跳转,不填默认不显示
                                getPage: function (page) {
                                    // 请求数据
                                    News_Announcement_List(page, true);
                                }
                            });
                          }
                        })
                } else {
                    layer.msg(result.msg, {
                        shade: 0.3,
                        time: 1000 // 1秒关闭
                    });
                    return;
                } 
            
            },
            error: function (error) {
                console.log(error);
            }
        })
    }

    //最新通告的更多
    $('#news_more2').on('click', function () {
        $('#span').html("");
        var title = "最新通告";
        $('#span').html(title);
        News_Announcement_List('')
    })
    //资源更新动态

    function News_Resources_List(page, isSecond) {
        $('#new_List').html();
        var data = {
            currentPage: page ? page : 1,
            pageRowNum: 24,
            newsType: "newsType3",
            //mtype: "News_Resources_GetNewsListByTitle",
            pageNum: page || 1,
            perPageNum: 24,
            Title: "",
            Author: "",
            startDate: "",
            endDate: "",
        }
        $.ajax({
            type: "post",
            async: false,
            url: baseUrl + "news/getNewsList",
            //url: "/BaseAshx/NewsManage/News_Resources.ashx",
            data: data,
            datatype: "json",
            success: function (result) {
                result = JSON.parse(result);
                if (result.code == 200) {
                    if (!result.data.table || result.data.total == 0) {
                        layer.msg('无数据', {
                            shade: 0.3,
                            time: 1000
                        });
                        return;
                    }
                    var html = "";
                    result.data.table.map(function (item, index) {
                        var colb = item.TITLE;
                        var id = item.TITLEID;
                        var content = "";
                        if (colb.lenght > 40) {
                            content = colb.substr(0, 40) + "...";
                        } else {
                            content = colb;
                        }
                        html += '<li class="list-li">' +
                            ' <span class="circle-span"></span>' +
                            '<span class="font-span"><a href="News_Content.html?id=' + id + '"> &nbsp;&nbsp;&nbsp;&nbsp;' + content + '</a></span>' +
                            '<span class="span-date">' + item.CREATETIME + '</span>' +
                            '</li>';
                        $('#new_List').html(html);
                        if (result.data.total > 24) {
                            var data = {
                                pageTotal: Math.ceil(result.data.total / 24),
                                pageAmount: 24, // 每页多少条
                                dataTotal: result.data.total,
                                curPage: 1
                            };
                            if (isSecond) {
                                return;
                            };


                            new Page({
                                id: 'page',
                                pageTotal: data.pageTotal, //必填,总页数（最少1页）
                                pageAmount: data.pageAmount, //每页多少条
                                dataTotal: data.dataTotal, //总共多少条数据（至少1条）
                                curPage: data.curPage, //初始页码,不填默认为1
                                pageSize: data.pageSize, //分页个数,不填默认为5
                                showPageTotalFlag: true, //是否显示数据统计,不填默认不显示
                                showSkipInputFlag: true, //是否支持跳转,不填默认不显示
                                getPage: function (page) {
                                    // 请求数据
                                    News_Announcement_List(page, true);
                                }
                            });
                        }
                    })
                } else {
                    layer.msg(result.msg, {
                        shade: 0.3,
                        time: 1000 // 1秒关闭
                    });
                    return;
                }
            },
            error: function (error) {
                console.log(error);
            }
        })
    }
    //资源更新动态的更多
    $('#news_more3').on('click', function () {
        $('#span').html("");
        var title = "资源更新动态";
        $('#span').html(title);
        News_Resources_List('');
    })

    //轮播图
    layui.use('carousel', function () {
        var carousel = layui.carousel;
        carousel.render({
            elem: '#test1',
            width: '360px', //设置容器宽度
            height:'235px', //设置容器高度
            arrow: 'always', //始终显示箭头
            anim: 'default',//切换方式左右切换
            autoplay: false,//自动切换
            interval: 2000,//时间间隔
            indicator: 'inside'//指示器位置 内部
        });
    });

    //获取地址栏参数
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var param = window.location.search.substr(1);
        var r = param.match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    if (getQueryString("mode")) {
        var mode = getQueryString("mode");
        $("#news_more" + mode).click();
    }
})